package com.cfets.annualAssessment.service;

import com.cfets.annualAssessment.entity.RoleRes;
import com.cfets.annualAssessment.mapper.RoleResMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by ShenYiChou on 2016/12/20.
 */
@Service
public class RoleResService {
    @Autowired
    private RoleResMapper roleResMapper;

    public List<RoleRes> findResByRole(String role){
        return roleResMapper.selectResByRole(role);
    }

    public boolean deleteMultiRoleRes(List<RoleRes> roleResList){
        boolean flag1 = true;
        for(RoleRes item:roleResList){
            int resId = item.getId();
            boolean flag0 = this.deleteRoleResById(resId);
            if (!flag0) {
                flag1 = false;
            }
        }
        return flag1;
    }

    public boolean insertMultiRoleRes(List<RoleRes> roleResList){
        boolean flag1 = true;
        for(RoleRes item:roleResList){
            boolean flag0 = this.newRoleRes(item);
            if (!flag0) {
                flag1 = false;
            }
        }
        return flag1;
    }
    public List<RoleRes> findResByRoleId(int id){
        return roleResMapper.selectResByRoleId(id);
    }

    public boolean newRoleRes(RoleRes roleRes){
        return  roleResMapper.insertSelective(roleRes)>0;
    }

    public boolean deleteRoleResById(int id){
        return roleResMapper.deleteByPrimaryKey(id)>0;
    }
}
